<?php

namespace App\Http\Controllers;

use App\Article;
use App\Category;
use App\Product;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ContentController extends Controller
{
    public function index(Request $request, $id)
    {
        $article = Article::find($id);
        $category = Category::find($article->category_id);
        $relatedArticles = Article::where([
            ['id', '!=', $id],
            ['category_id', '=', $article->category_id]
        ])->take(10)->get();
        return view('content', [
            'id' => $article->category_id,
            'article' => $article,
            'category' => $category,
            'relatedArticles' => $relatedArticles
        ]);
    }

    public function search(Request $request)
    {
        $lists3 = Article::where('category_id', '3')
            ->orderBy('updated_at', 'desc')
            ->take(10)->get();
        $productId = $request->input('product');
        $product = Product::find($productId);
        return view('search', [
            'id' => '0',
            'lists3' => $lists3,
            'product' => $product
        ]);
    }
}